import logging
import os

import allure
import pymysql
import requests

from config.config import *


@allure.step("2，发送http请求")
def send_http_request(**request_data):
    res = requests.request(**request_data)
    logging.info(f'2.发送HTTP请求，响应文本为:{res.text}')
    return res


def send_jdbc_request(sql, index=0):
    conn = pymysql.Connect(
        # host=DB_HOST,
        # port=DB_PORT,
        # database=DB_NAME,
        # user=DB_USER,
        # password=DB_PASSWORD,
        **eval(os.environ["DB"]),
        charset="utf8"
    )
    # 3，创建游标-驴
    cur = conn.cursor()
    # 4，核心流程-执行sql语句，并处理结果
    cur.execute(sql)
    result = cur.fetchone()
    # 5，关闭游标
    cur.close()
    # 6，关闭连接
    conn.close()
    return result[index]
